﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVC_Filter.Infrastructure
{
    public class ProfileActionAttribute:FilterAttribute,IActionFilter
    {
        private Stopwatch timer;
        public void OnActionExecuted(ActionExecutedContext filterContext)//Action Filter
        {
            timer.Stop();
            if (filterContext.Exception==null)
            {
                filterContext.RequestContext.HttpContext.Response.Write("The run time is "+timer.Elapsed.TotalSeconds);
            }
        }

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            
            timer = Stopwatch.StartNew();
        }
    }
}